local moyan = fk.CreateSkill{
  name = "rfenghou_3d11j__moyan",
}

moyan:addEffect(fk.RoundStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(moyan.name)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = moyan.name,
      prompt = "#rfenghou_3d11j__moyan-invoke"
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:turnOverCardsFromDrawPile(player, cards, moyan.name, true, room:getAllPlayers(false))
    local to = room:askToChoosePlayers(player, {
      targets = room:getAlivePlayers(false),
      min_num = 1,
      max_num = 1,
      skill_name = moyan.name,
      prompt = "#rfenghou_3d11j__moyan-target",
      cancelable = false
    })[1]
    if not to then to = player end
    local obtains = room:askToChooseCards(to, {
      target = to,
      flag = {
        card_data = { { moyan.name, cards } }
      },
      min = 1,
      max = 3,
      skill_name = moyan.name,
      prompt = "#rfenghou_3d11j__moyan-obtain"
    })
    room:obtainCard(to, obtains, true, fk.ReasonPrey, to, moyan.name)
    room:setPlayerMark(to, "@rfenghou_3d11j__moyan-round", #obtains)
  end
})
moyan:addEffect(fk.DamageInflicted, {
  is_delay_effect = true,
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    if target == player then
      local mark = player:getMark("@rfenghou_3d11j__moyan-round")
      return mark ~= 0 and player:getHandcardNum() <= mark
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data:changeDamage(player:getMark("@rfenghou_3d11j__moyan-round"))
  end
})

Fk:loadTranslationTable{
  ["rfenghou_3d11j__moyan"] = "末焱",
  [":rfenghou_3d11j__moyan"] = "每轮开始时，你可以亮出牌堆顶的三张牌，令一名角色选择并获得其中至少一张牌；本轮其受到伤害时，若其手牌数不大于X，此伤害+X（X为其此次得到的牌数）。",

  ["#rfenghou_3d11j__moyan-invoke"] = "末焱：你可以亮出牌堆顶的三张牌并令一名角色获得其中至少一张牌",
  ["#rfenghou_3d11j__moyan-target"] = "末焱：你可以令一名角色获得其中至少一张牌",
  ["#rfenghou_3d11j__moyan-obtain"] = "末焱：请获得至少一张牌，若你的手牌数比这些手牌数少则会被加伤",

  ["@rfenghou_3d11j__moyan-round"] = "末焱",
}

return moyan
